#!/bin/sh

# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later

if [ -z "$PYTHON_EXE" ]; then
    PYTHON_EXE="python3"
fi

function terminate_jobs {
    running_jobs=$(jobs -pr)
    if [ -n "$running_jobs" ]; then
        kill $running_jobs
    fi
}

trap terminate_jobs EXIT

export \
    LC_ALL=C.UTF8 \
    NOSE_EVAL_ATTR \
    NOSE_LOGFORMAT='%(asctime)s %(levelname)-5s (%(threadName)s) [%(name)s] %(message)s (%(module)s:%(lineno)d)' \
    NOSE_VERBOSE=${NOSE_VERBOSE:-1} \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONPATH="@top_srcdir@/static/usr/share/vdsm:@top_srcdir@/lib:@top_srcdir@/vdsm_api:$PYTHONPATH" \
    $NULL

if [ -n "$TIMEOUT" ]; then
    PYTHON_EXE="$PYTHON_EXE py-watch $TIMEOUT $PYTHON_EXE"
fi

$PYTHON_EXE "@top_srcdir@"/tests/testrunner.py --local-modules "$@"
